﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Hotel.Models.Entity;
using Hotel.Models.Services;

namespace Hotel.Controllers
{
    public class RoomController : BaseController
    {
        //
        // GET: /Room/

        public ActionResult Room()
        {
            List<Floor> lf = new List<Floor>();
            List<RoomType> lrt = new List<RoomType>();
            List<Room> lr = new List<Room>();
            lr = RoomService.GetListRoom();
            lrt = RoomTypeService.GetListRoomType();
            lf = FloorService.GetListFloor();
            ViewData["ListFloor"] = lf;
            ViewData["ListRoomType"] = lrt;
            ViewData["ListRoom"] = lr;
            return View();
        }

        public ActionResult ViewPage1()
        {
            List<Floor> lf = new List<Floor>();
            List<RoomType> lrt = new List<RoomType>();
            List<Room> lr = new List<Room>();
            lr = RoomService.GetListRoom();
            lrt = RoomTypeService.GetListRoomType();
            lf = FloorService.GetListFloor();
            ViewData["ListFloor"] = lf;
            ViewData["ListRoomType"] = lrt;
            ViewData["ListRoom"] = lr;
            return View();
        }

        [HttpPost]
        public bool EditFloor(int id, string name)
        {
            Floor fl = FloorService.GetFloorDetail(id);
            fl.Name = name;
            return FloorService.SaveFloor(fl,true);
        }
        [HttpPost]
        public bool AddFloor(string name)
        {
            Floor fl = new Floor(0,name);
            
            return FloorService.SaveFloor(fl, false);
        }
        [HttpPost]
        public bool AddRoomType(string name)
        {
            RoomType rt = new RoomType(name);

            return RoomTypeService.SaveRoomType(rt, false);
        }

        [HttpPost]
        public bool EditRoomType(int id, string name)
        {
            RoomType rt = RoomTypeService.GetRoomTypeDetail(id);
            rt.RoomTypeName = name;
            return RoomTypeService.SaveRoomType(rt, true);
        }

        [HttpPost]
        public bool AddRoom(int floorId, int roomTypeId, string name, string amenities, string information, int noBed, int noPerson)
        {
            Room room = new Room();
            Floor fl = FloorService.GetFloorDetail(floorId);
            RoomType rt = RoomTypeService.GetRoomTypeDetail(roomTypeId);
            room.Floor = fl;
            room.RoomType = rt;
            room.Name = name;
            room.Amenities = amenities;
            room.Information = information;
            room.NoBeds = noBed;
            room.NoPerson = noPerson;
            return RoomService.SaveRoom(room,false);
        }

        [HttpPost]
        public bool EditRoom(int id, int floorId, int roomTypeId, string name, string amenities, string information, int noBed, int noPerson)
        {            
            Floor fl = FloorService.GetFloorDetail(floorId);
            RoomType rt = RoomTypeService.GetRoomTypeDetail(roomTypeId);
            Room room = RoomService.GetDetailRoom(id);
            room.Floor = fl;
            room.RoomType = rt;
            room.Name = name;
            room.Amenities = amenities;
            room.Information = information;
            room.NoBeds = noBed;
            room.NoPerson = noPerson;
            return RoomService.SaveRoom(room, true);
        }
    }
}
